package com.zjm.creational.simple_factory.pizzastore.order;

import com.zjm.creational.simple_factory.pizzastore.pizza.CheesePizza;
import com.zjm.creational.simple_factory.pizzastore.pizza.GreekPizza;
import com.zjm.creational.simple_factory.pizzastore.pizza.PepperPizza;
import com.zjm.creational.simple_factory.pizzastore.pizza.Pizza;

/**
 * 简单工厂类
 */
public class SimpleFactory {

    public Pizza createPizza(String orderType) {
        System.out.println("使用简单工厂模式");
        Pizza pizza = null;
        if ("greek".equals(orderType)) {
            pizza = new GreekPizza();
            pizza.setName("Greek");
        } else if ("cheese".equals(orderType)) {
            pizza = new CheesePizza();
            pizza.setName("Cheese");
        } else if ("pepper".equals(orderType)) {
            pizza = new PepperPizza();
            pizza.setName("Pepper");
        }
        return pizza;
    }

    /**
     * 简单工厂模式也叫静态工厂模式
     * @param orderType
     * @return
     */
    public static Pizza createPizza2(String orderType) {
        System.out.println("使用简单工厂模式2---静态方法");
        Pizza pizza = null;
        if ("greek".equals(orderType)) {
            pizza = new GreekPizza();
            pizza.setName("Greek");
        } else if ("cheese".equals(orderType)) {
            pizza = new CheesePizza();
            pizza.setName("Cheese");
        } else if ("pepper".equals(orderType)) {
            pizza = new PepperPizza();
            pizza.setName("Pepper");
        }
        return pizza;
    }
}
